<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<div th:replace="XAdmin/commons/header"></div>
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
<style>
    [v-cloak] {
        display: none;
    }
</style>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">预定信息</a>
                <a>
                    <cite>预定设置</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div id="app" class="layui-row layui-col-space15">
        <br><br>
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form ">
                        <div class="layui-input-inline layui-show-xs-block">
                            <input class="layui-input" placeholder="预约日期" id="reserveTime" name="reserveTime">
                        </div>

                        <div class="layui-input-inline layui-show-xs-block">
                            <button class="layui-btn" type="button" lay-filter="sreach" data-type="reload"
                                    onclick="reload()">
                                <i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body ">
                    <button style="float: right;" class="layui-btn"
                            onclick="xadmin.open('添加数据', 'reservation_setting_list_add','700','500')"><i
                            class="layui-icon">&#xe608;</i>添加
                    </button>
                    <br><br>
                    <table class="layui-table" id="test" lay-data="test" lay-filter="test">
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a> &nbsp;
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use(['laydate', 'form'],
        function () {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#reserveTime', //指定元素
                trigger: 'click',
                type: 'date',
            });
        });

    layui.use(['form'],
        function () {
            layui.use('table', function () {
                table = layui.table;
                //方法级渲染
                var t1 = table.render({
                    elem: '#test',
                    url: $baseUrl + 'reserveSetting/findReserveSettingList',
                    where: {
                        userId: $userId,
                    },
                    headers: {
                        token: $token
                    },
                    // toolbar: true,
                    toolbar: '#toolbarDemo',
                    cols: [
                        [{
                            field: 'reserveTime',
                            title: '预约时间',
                            align: 'center',
                        },
                            {
                                field: 'reserveNumber',
                                title: '可预约人数',
                                align: 'center',
                            },
                            {
                                field: 'yetReserveNumber',
                                title: '已预约人数',
                                align: 'center',
                            },
                            {
                                field: 'createTime',
                                title: '添加时间',
                                align: 'center',
                            },
                            {
                                field: 'updateTime',
                                title: '修改时间',
                                align: 'center',
                            },
                            {
                                field: 'status',
                                title: '操作',
                                templet: '#barDemo',
                                align: 'center',

                            }]
                    ],
                    request: {
                        pageName: 'pageNum', //页码的参数名称，默认：page
                        limitName: 'pageSize',
                    },
                    response: {
                        statusName: 'code' //规定数据状态的字段名称，默认：code
                        ,
                        statusCode: 20000 //规定成功的状态码，默认：0
                        ,
                        msgName: 'msg' //规定状态信息的字段名称，默认：msg
                        ,
                        countName: 'total' //规定数据总数的字段名称，默认：count
                        ,
                        dataName: 'data', //规定数据列表的字段名称，默认：data
                    },
                    id: 'test',
                    page: true,
                    height: 'auto',
                    even: true,
                    done: function (res, curr, count) {
                        //是否有权限或权限是否失效
                        authorizeState();
                    }
                });


                //监听工具条
                table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                    let data = obj.data; //获得当前行数据
                    let layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                    // let tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
                    if (layEvent === 'del') { //删除
                        layer.confirm('是否确认删除 【' + data.reserveTime + '】 ？', {
                            icon: 3,
                            title: '提示'
                        }, function (index) {
                            let request = {
                                url: "reserveSetting/delReserveSetting/" + data.id,
                                data: {
                                    userId: $userId,
                                },
                                method: "DELETE",
                            };
                            sendRequest(request, (data) => {
                                if (data.code === 20000) {
                                    layer.msg("删除成功", {
                                        icon: 1
                                    });
                                    t1.reload();
                                } else {
                                    layer.msg("删除失败，请稍后再试！", {
                                        icon: 5
                                    });
                                }
                            });
                            layer.close(index);
                        });
                    } else if (layEvent === 'edit') { //编辑
                        xadmin.open('修改数据', 'reservation_setting_list_edit?recordId=' + data.id, '700', '500')
                    }
                });

            });


        });

    function reload(value) {
        table.reload('test', {
            where: {
                reserveTime: $("input[name=reserveTime]").val(),
            }
        });
    }

</script>
</html>